<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,initial-scale=1.0,width=device-width" />
    <meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
    <title>申请成为商家</title>
    <link rel="stylesheet" type="text/css" href="../../../css/aui/aui.css" />
    <link rel="stylesheet" type="text/css" href="../../../css/html/issued/post_your_want_frm.css" />
    <style>
        .up_image_box {
            display: flex;
            justify-content: space-between;
        }

        .up_image {
            width: calc(33.33% - 0.4rem);
            height: 29vw;
            border: 1px solid #E1E1E1;
            margin-right: 0.6rem;
            margin-bottom: 1rem;
            display: flex;
            justify-content: center;
            align-items: center;
        }

        .up_image:last-child {
            margin-right: 0;
        }
    </style>
</head>

<body>
    <div id="app">
        <div style="background:#ebebeb;padding:0.5rem 0.75rem;" v-if="info.admin_notes">
            <div style="margin:0.5rem 0;">审核结果：</div>
            <div style="border:1px solid #999;padding:0.5rem;">{{info.admin_notes}}</div>
        </div>
        <div class="aui-content aui-margin-b-15">
            <ul class="aui-list aui-form-list">
                <li class="aui-list-item">
                    <div class="aui-list-item-inner">
                        <div class="aui-list-item-label">店铺名称</div>
                        <div class="aui-list-item-input">
                            <input type="text" v-model="info.shop_name" placeholder="请填写店铺名称">
                        </div>
                    </div>
                </li>
                <li class="aui-list-item" @click="openCity()">
                    <div class="aui-list-item-inner">
                        <div class="aui-list-item-label">店铺区域</div>
                        <div class="aui-list-item-input">
                            <input v-model="info.region" disabled type="text" placeholder="请选择">
                        </div>
                    </div>
                </li>
                <li class="aui-list-item">
                    <div class="aui-list-item-inner">
                        <div class="aui-list-item-label">店铺地址</div>
                        <div class="aui-list-item-input">
                            <input type="text" v-model="info.shop_address" placeholder="请填写店铺详细地址">
                        </div>
                    </div>
                </li>
                <li class="aui-list-item">
                    <div class="aui-list-item-inner">
                        <div class="aui-list-item-label">店铺联系人</div>
                        <div class="aui-list-item-input">
                            <input type="text" v-model="info.user_name" placeholder="请填写店铺联系人">
                        </div>
                    </div>
                </li>
                <li class="aui-list-item">
                    <div class="aui-list-item-inner">
                        <div class="aui-list-item-label">联系电话</div>
                        <div class="aui-list-item-input">
                            <input type="tel" v-model="info.user_tel" placeholder="请填写手机号">
                        </div>
                    </div>
                </li>
                <li class="aui-list-item">
                    <div class="aui-list-item-inner">
                        <div class="aui-list-item-label">所属行业</div>
                        <div class="aui-list-item-input">
                            <input type="text" v-model="info.industry_notes" placeholder="请简单描述所属行业">
                        </div>
                    </div>
                </li>
            </ul>

            <div class="aui-content-padded">
                <div>
                    <div style="margin:1rem 0 0.5rem 0;">营业执照及身份证正反面</div>
                    <div class="up_image_box">
                        <div class="up_image" onclick="addImg(this,0)">
                            <img v-if='info.endowments_image_array[0]' :src="info.endowments_image_array[0]" alt="" style="width:100%;height:100%;">
                            <img v-else src="../../../image/icon/shangchuan1.png" alt="">
                        </div>
                        <div class="up_image" onclick="addImg(this,1)">
                            <img v-if='info.endowments_image_array[1]' :src="info.endowments_image_array[1]" alt="" style="width:100%;height:100%;">
                            <img v-else src="../../../image/icon/shangchuan1.png" alt="">
                        </div>
                        <div class="up_image" onclick="addImg(this,2)">
                            <img v-if='info.endowments_image_array[2]' :src="info.endowments_image_array[2]" alt="" style="width:100%;height:100%;">
                            <img v-else src="../../../image/icon/shangchuan1.png" alt="">
                        </div>
                    </div>
                </div>
                <div class="btn" @click="submit()" v-if="type==2">提交</div>
                <div class="btn" @click="submit()" v-if="type==1 && info.shop_status==2">提交</div>
            </div>

        </div>
    </div>
</body>
<script src="../../../script/api.js" charset="utf-8"></script>
<script src="../../../script/aui/aui-tab.js" charset="utf-8"></script>
<script src="../../../script/common/jquery-3.3.1.min.js" charset="utf-8"></script>
<script src="../../../script/common/check.js" charset="utf-8"></script>
<script src="../../../script/common/common.js" charset="utf-8"></script>
<script src="../../../script/common/config.js" charset="utf-8"></script>
<script src="../../../script/common/vue.min.js" charset="utf-8"></script>
<script>
    apiready = function() {
        api.parseTapmode();
        vm.init();
    }

    var vm = new Vue({
        el: "#app",
        data: {
            type: '',
            info: {
                user_id: '',
                shop_name: '',
                region_provinceid: '',
                region_cityid: '',
                region_areaid: '',
                region: '',
                shop_address: '',
                user_tel: '',
                user_name: '',
                industry_notes: '',
                endowments_image_array: [],
            }
        },
        methods: {
            init() {
                this.type = api.pageParam.type;
                if (api.pageParam.type === 1) {
                    this.getApplyDetail();
                } else if (api.pageParam.type === 2) {
                    var userInfo = get_local('userInfo');
                    this.info.user_id = userInfo.user_id;
                }
            },
            getApplyDetail() {
                var that = this;
                var userInfo = get_local('userInfo');
                _ajax(Config.api.ShopApplyDetail, {
                    user_id: userInfo.user_id
                }, function(ret) {
                  console.log(JSON.stringify(ret));
                    if (ret.code === 200) {
                        that.info = ret.data;
                    }
                });
            },
            submit() {
                if (!is_define(this.info.shop_name)) {
                    $toast("请输入店铺名称");
                    return;
                } else if (!is_define(this.info.region)) {
                    $toast("请输入店铺所在区域");
                    return;
                } else if (!is_define(this.info.shop_address)) {
                    $toast("请输入店铺地址");
                    return;
                } else if (!is_define(this.info.user_name)) {
                    $toast("请输入联系人");
                    return;
                } else if (!is_define(this.info.user_tel)) {
                    $toast("请输入联系人电话");
                    return;
                } else if (!checkMobile(this.info.user_tel)) {
                    $toast("请输入正确的手机号");
                    return;
                } else if (!is_define(this.info.industry_notes)) {
                    $toast("请简单描述所属行业");
                    return;
                }

                if (api.pageParam.type === 1) {
                    _ajax(Config.api.ShopUpdate, this.info, function(ret) {
                        if (ret.code === 200) {
                            $toast("更新成功");
                            setTimeout(function() {
                                close_w();
                            }, 1000);
                        } else {
                            $toast(ret.msgs);
                        }
                    });
                } else if (api.pageParam.type === 2) {
                    _ajax(Config.api.AhopApply, this.info, function(ret) {
                        if (ret.code === 200) {
                            $toast("提交成功");
                            setTimeout(function() {
                                close_w();
                            }, 1000);
                        } else {
                            $toast(ret.msgs);
                        }
                    });
                }

            },
            openCity() {
                var url = '../../city/city_win.html';
                api.openFrame({
                    name: 'mask',
                    url: url,
                    rect: {
                        x: 0,
                        y: api.winHeight - api.frameHeight,
                        w: 'auto',
                        h: 'auto'
                    },
                    bgColor: 'rgba(0,0,0,0.5)',
                    pageParam: {
                        name: api.winName,
                        frameName: api.frameName,
                    }
                });
            },
        }
    });

    function addImg(e, i) {
        imageUpload(Config.api.ImageUploadcommon, function(ret) {
            $(e).find('img').attr('src', ret.data.imgurl).css({'width': '100%', 'height': '100%'});
            vm.info.endowments_image_array[i] = ret.data.imgurl;
        });
    }

    function setCity(province, city, area) {
        vm.info.region_provinceid = province.code;
        vm.info.region_cityid = city.code;
        vm.info.region_areaid = area.code;

        vm.info.region = province.name + '-' + city.name + '-' + area.name
    }
</script>

</html>
